using System.Collections.Generic;
using UnityEngine;

namespace MaterialUI
{
	public static class PrefabManager
	{
		public static class ResourcePrefabs
		{
			public const string progressIndicatorCircular = "Progress Indicators/Circle Progress Indicator";

			public const string progressIndicatorLinear = "Progress Indicators/Linear Progress Indicator";

			public const string dialogAlert = "Dialogs/DialogAlert";

			public const string dialogProgress = "Dialogs/DialogProgress";

			public const string dialogSimpleList = "Dialogs/DialogSimpleList";

			public const string dialogCheckboxList = "Dialogs/DialogCheckboxList";

			public const string dialogRadioList = "Dialogs/DialogRadioList";

			public const string dialogTimePicker = "Dialogs/Pickers/DialogTimePicker";

			public const string dialogDatePicker = "Dialogs/Pickers/DialogDatePicker";

			public const string dialogPrompt = "Dialogs/DialogPrompt";

			public const string disabledPanel = "DisabledPanel";

			public const string sliderDot = "SliderDot";

			public const string dropdownPanel = "Menus/Dropdown Panel";

			public const string snackbar = "Snackbar";

			public const string toast = "Toast";
		}

		private static readonly List<GameObject> m_Prefabs = new List<GameObject>();

		private static readonly List<string> m_Names = new List<string>();

		public static GameObject GetGameObject(string nameWithPath)
		{
			GameObject gameObject = null;
			if (!m_Names.Contains(nameWithPath))
			{
				gameObject = Resources.Load<GameObject>(nameWithPath);
				if (gameObject != null)
				{
					m_Prefabs.Add(gameObject);
					m_Names.Add(nameWithPath);
				}
			}
			else
			{
				for (int i = 0; i < m_Prefabs.Count; i++)
				{
					if (m_Names[i] == nameWithPath && m_Prefabs[i] != null)
					{
						gameObject = m_Prefabs[i];
					}
				}
			}
			return gameObject;
		}

		public static GameObject InstantiateGameObject(string nameWithPath, Transform parent)
		{
			GameObject gameObject = GetGameObject(nameWithPath);
			if (gameObject == null)
			{
				return null;
			}
			gameObject = Object.Instantiate(gameObject);
			if (parent == null)
			{
				return gameObject;
			}
			gameObject.transform.SetParent(parent);
			gameObject.transform.localScale = Vector3.one;
			gameObject.transform.localEulerAngles = Vector3.zero;
			gameObject.transform.localPosition = Vector3.zero;
			return gameObject;
		}
	}
}
